/**
 *******************************************************************************
 * @FileName  : tlsr825x_flash.h
 * @Author    : GaoQiu
 * @CreateDate: 2020-09-10
 * @Copyright : Copyright(C) GaoQiu
 *              All Rights Reserved.
 *
 *******************************************************************************
 *
 * The information contained herein is confidential and proprietary property of
 * GaoQiu and is available under the terms of Commercial License Agreement
 * between GaoQiu and the licensee in separate contract or the terms described
 * here-in.
 *
 * This heading MUST NOT be removed from this file.
 *
 * Licensees are granted free, non-transferable use of the information in this
 * file under Mutual Non-Disclosure Agreement. NO WARRENTY of ANY KIND is provided.
 *
 *******************************************************************************
 */
#ifndef __TLSR82XX_FLASH_H
#define __TLSR82XX_FLASH_H

#include "tlsr825x.h"


/*!  Flash operation command. */
#define FLASH_CMD_WRITE_STATUS		    0x01
#define FLASH_CMD_WRITE				    0x02
#define FLASH_CMD_READ				    0x03
#define FLASH_CMD_WRITE_DISABLE	 	    0x04
#define FLASH_CMD_READ_STATUS			0x05
#define FLASH_CMD_WRITE_ENABLE 		 	0x06
#define FLASH_CMD_SECT_ERASE			0x20
#define FLASH_CMD_GD_PUYA_READ_UID		0x4B	//Flash Type = GD/PUYA
#define FLASH_CMD_32KBLK_ERASE			0x52
#define FLASH_CMD_XTX_READ_UID			0x5A	//Flash Type = XTX
#define FLASH_CMD_CHIP_ERASE			0x60    //or 0xc7
#define FLASH_CMD_PAGE_ERASE			0x81    //caution: only P25Q40L support this function
#define FLASH_CMD_64KBLK_ERASE			0xD8
#define FLASH_CMD_POWER_DOWN		    0xB9
#define FLASH_CMD_POWER_DOWN_RELEASE	0xAB
#define FLASH_CMD_GET_JEDEC_ID			0x9F

/*! Flash parameter. */
#define FLASH_SECTOR_SIZE               4096
#define FLASH_PAGE_SIZE                 256

/**
 * @brief : erase flash sector(4k).
 * @param : addr    the address of flash.
 * @return: none.
 */
RAM_CODE void FLASH_EraseSector(uint32_t addr);

/**
 * @brief : write flash page.
 * @param : addr     the address of flash.
 * @param : pData    Pointer point to data buffer.
 * @param : len      the length of data.
 * @return: none.
 */
void FLASH_WritePage(uint32_t addr, uint8_t *pData, uint32_t len);

/**
 * @brief : read flash page.
 * @param : addr     the address of flash.
 * @param : pData    Pointer point to data buffer.
 * @param : len      the length of data.
 * @return: none.
 */
void FLASH_ReadPage(uint32_t addr, uint8_t *pData, uint32_t len);


#endif
